//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.tencent.bugly.crashreport.biz;

import android.app.Activity;
import android.app.Application;
import android.app.Application.ActivityLifecycleCallbacks;
import android.content.Context;
import android.os.Bundle;
import android.os.Build.VERSION;
import com.tencent.bugly.BuglyStrategy;
import com.tencent.bugly.crashreport.biz.a.c;
import com.tencent.bugly.crashreport.common.strategy.StrategyBean;
import com.tencent.bugly.proguard.w;
import com.tencent.bugly.proguard.x;
import com.tencent.bugly.proguard.z;
import java.util.List;

public class b {
    private static boolean b;
    private static int c = 10;
    private static long d = 300000L;
    private static long e = 30000L;
    private static long f = 0L;
    private static int g;
    private static long h;
    private static long i;
    public static a a;
    private static long j = 0L;
    private static ActivityLifecycleCallbacks k = null;
    private static Class<?> l = null;
    private static boolean m = true;

    static String a(String str, String str2) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(z.a());
        stringBuilder.append("  ");
        stringBuilder.append(str);
        stringBuilder.append("  ");
        stringBuilder.append(str2);
        stringBuilder.append("\n");
        return stringBuilder.toString();
    }

    public b() {
    }

    private static void c(Context var0, BuglyStrategy var1) {
        boolean var2 = true;
        boolean var3 = false;
        if (var1 != null) {
            var3 = var1.recordUserInfoOnceADay();
            var2 = var1.isEnableUserInfo();
        }

        a var16;
        if (var3) {
            boolean var10000;
            label101: {
                com.tencent.bugly.crashreport.common.info.a var18;
                String var4 = (var18 = com.tencent.bugly.crashreport.common.info.a.a(var0)).d;
                List var5;
                if ((var5 = a.a(var4)) != null) {
                    for(int var6 = 0; var6 < var5.size(); ++var6) {
                        UserInfoBean var7;
                        if ((var7 = (UserInfoBean)var5.get(var6)).n.equals(var18.k) && var7.b == 1) {
                            long var10;
                            if ((var10 = z.b()) <= 0L) {
                                break;
                            }

                            if (var7.e >= var10) {
                                if (var7.f <= 0L) {
                                    w var13;
                                    if ((var13 = w.a()) != null) {
                                        var13.a(new a.n2(a));
                                    }
                                }

                                var10000 = false;
                                break label101;
                            }
                        }
                    }
                }

                var10000 = true;
            }

            if (!var10000) {
                return;
            }

            var2 = false;
        }

        com.tencent.bugly.crashreport.common.info.a var17;
        if ((var17 = com.tencent.bugly.crashreport.common.info.a.b()) != null) {
            String var19 = null;
            boolean var20 = false;
            StackTraceElement[] var22;
            int var23 = (var22 = Thread.currentThread().getStackTrace()).length;

            for(int var24 = 0; var24 < var23; ++var24) {
                StackTraceElement var11;
                if ((var11 = var22[var24]).getMethodName().equals("onCreate")) {
                    var19 = var11.getClassName();
                }

                if (var11.getClassName().equals("android.app.Activity")) {
                    var20 = true;
                }
            }

            if (var19 != null) {
                if (var20) {
                    var17.a(true);
                } else {
                    var19 = "background";
                }
            } else {
                var19 = "unknown";
            }

            var17.q = var19;
        }

        if (var2) {
            Application var21 = null;
            if (VERSION.SDK_INT >= 14) {
                if (var0.getApplicationContext() instanceof Application) {
                    var21 = (Application)var0.getApplicationContext();
                }

                if (var21 != null) {
                    try {
                        if (k == null) {
                            k = new ActivityLifecycleCallbacks() {
                                public final void onActivityStopped(Activity var1) {
                                }

                                public final void onActivityStarted(Activity var1) {
                                }

                                public final void onActivitySaveInstanceState(Activity var1, Bundle var2) {
                                }

                                public final void onActivityResumed(Activity var1) {
                                    String var2 = "unknown";
                                    if (var1 != null) {
                                        var2 = var1.getClass().getName();
                                    }

                                    if (com.tencent.bugly.crashreport.biz.b.l == null || com.tencent.bugly.crashreport.biz.b.l.getName().equals(var2)) {
                                        x.c(">>> %s onResumed <<<", new Object[]{var2});
                                        com.tencent.bugly.crashreport.common.info.a var13;
                                        if ((var13 = com.tencent.bugly.crashreport.common.info.a.b()) != null) {
                                            var13.E.add(com.tencent.bugly.crashreport.biz.b.a(var2, "onResumed"));
                                            var13.a(true);
                                            var13.q = var2;
                                            var13.r = System.currentTimeMillis();
                                            var13.u = var13.r - com.tencent.bugly.crashreport.biz.b.i;
                                            long var4 = var13.r - com.tencent.bugly.crashreport.biz.b.h;
                                            long var6 = com.tencent.bugly.crashreport.biz.b.f > 0L ? com.tencent.bugly.crashreport.biz.b.f : com.tencent.bugly.crashreport.biz.b.e;
                                            if (var4 > var6) {
                                                var13.d();
                                                com.tencent.bugly.crashreport.biz.b.g++;
                                                x.a("[session] launch app one times (app in background %d seconds and over %d seconds)", new Object[]{var4 / 1000L, com.tencent.bugly.crashreport.biz.b.e / 1000L});
                                                if (com.tencent.bugly.crashreport.biz.b.g % com.tencent.bugly.crashreport.biz.b.c == 0) {
                                                    com.tencent.bugly.crashreport.biz.b.a.a(4, com.tencent.bugly.crashreport.biz.b.m, 0L);
                                                    return;
                                                }

                                                com.tencent.bugly.crashreport.biz.b.a.a(4, false, 0L);
                                                long var8;
                                                if ((var8 = System.currentTimeMillis()) - com.tencent.bugly.crashreport.biz.b.j > com.tencent.bugly.crashreport.biz.b.d) {
                                                    com.tencent.bugly.crashreport.biz.b.j = var8;
                                                    x.a("add a timer to upload hot start user info", new Object[0]);
                                                    if (com.tencent.bugly.crashreport.biz.b.m) {
                                                        long var11 = com.tencent.bugly.crashreport.biz.b.d;
                                                        w.a().a(new a.a1(com.tencent.bugly.crashreport.biz.b.a, (UserInfoBean)null, true), var11);
                                                    }
                                                }
                                            }

                                        }
                                    }
                                }

                                public final void onActivityPaused(Activity var1) {
                                    String var2 = "unknown";
                                    if (var1 != null) {
                                        var2 = var1.getClass().getName();
                                    }

                                    if (com.tencent.bugly.crashreport.biz.b.l == null || com.tencent.bugly.crashreport.biz.b.l.getName().equals(var2)) {
                                        x.c(">>> %s onPaused <<<", new Object[]{var2});
                                        com.tencent.bugly.crashreport.common.info.a var3;
                                        if ((var3 = com.tencent.bugly.crashreport.common.info.a.b()) != null) {
                                            var3.E.add(com.tencent.bugly.crashreport.biz.b.a(var2, "onPaused"));
                                            var3.a(false);
                                            var3.s = System.currentTimeMillis();
                                            var3.t = var3.s - var3.r;
                                            com.tencent.bugly.crashreport.biz.b.h = var3.s;
                                            if (var3.t < 0L) {
                                                var3.t = 0L;
                                            }

                                            if (var1 != null) {
                                                var3.q = "background";
                                            } else {
                                                var3.q = "unknown";
                                            }
                                        }
                                    }
                                }

                                public final void onActivityDestroyed(Activity var1) {
                                    String var2 = "unknown";
                                    if (var1 != null) {
                                        var2 = var1.getClass().getName();
                                    }

                                    if (com.tencent.bugly.crashreport.biz.b.l == null || com.tencent.bugly.crashreport.biz.b.l.getName().equals(var2)) {
                                        x.c(">>> %s onDestroyed <<<", new Object[]{var2});
                                        com.tencent.bugly.crashreport.common.info.a var3;
                                        if ((var3 = com.tencent.bugly.crashreport.common.info.a.b()) != null) {
                                            var3.E.add(com.tencent.bugly.crashreport.biz.b.a(var2, "onDestroyed"));
                                        }

                                    }
                                }

                                public final void onActivityCreated(Activity var1, Bundle var2) {
                                    String var4 = "unknown";
                                    if (var1 != null) {
                                        var4 = var1.getClass().getName();
                                    }

                                    if (com.tencent.bugly.crashreport.biz.b.l == null || com.tencent.bugly.crashreport.biz.b.l.getName().equals(var4)) {
                                        x.c(">>> %s onCreated <<<", new Object[]{var4});
                                        com.tencent.bugly.crashreport.common.info.a var3;
                                        if ((var3 = com.tencent.bugly.crashreport.common.info.a.b()) != null) {
                                            var3.E.add(com.tencent.bugly.crashreport.biz.b.a(var4, "onCreated"));
                                        }

                                    }
                                }
                            };
                        }

                        var21.registerActivityLifecycleCallbacks(k);
                    } catch (Exception var15) {
                        if (!x.a(var15)) {
                            var15.printStackTrace();
                        }
                    }
                }
            }
        }

        if (m) {
            i = System.currentTimeMillis();
            a.a(1, false, 0L);
            x.a("[session] launch app, new start", new Object[0]);
            a.a();
            long var25 = 21600000L;
            var16 = a;
            w.a().a(new a.c(var16, var25), var25);
        }

    }

    public static void a(final Context var0, final BuglyStrategy var1) {
        if (!b) {
            m = com.tencent.bugly.crashreport.common.info.a.a(var0).e;
            a = new a(var0, m);
            b = true;
            long var2 = 0L;
            if (var1 != null) {
                l = var1.getUserInfoActivity();
                var2 = var1.getAppReportDelay();
            }

            if (var2 <= 0L) {
                c(var0, var1);
            } else {
                w.a().a(new Runnable() {
                    public final void run() {
                        com.tencent.bugly.crashreport.biz.b.c(var0, var1);
                    }
                }, var2);
            }
        }
    }

    public static void a(long var0) {
        if (var0 < 0L) {
            var0 = com.tencent.bugly.crashreport.common.strategy.a.a().c().q;
        }

        f = var0;
    }

    public static void a(StrategyBean var0, boolean var1) {
        if (a != null && !var1) {
            a var3 = a;
            w var2;
            if ((var2 = w.a()) != null) {
                var2.a(new a.n2(var3));
            }
        }

        if (var0 != null) {
            if (var0.q > 0L) {
                e = var0.q;
            }

            if (var0.w > 0) {
                c = var0.w;
            }

            if (var0.x > 0L) {
                d = var0.x;
            }

        }
    }

    public static void a() {
        if (a != null) {
            a.a(2, false, 0L);
        }

    }

    public static void a(Context var0) {
        if (b && var0 != null) {
            Application var1 = null;
            if (VERSION.SDK_INT >= 14) {
                if (var0.getApplicationContext() instanceof Application) {
                    var1 = (Application)var0.getApplicationContext();
                }

                if (var1 != null) {
                    try {
                        if (k != null) {
                            var1.unregisterActivityLifecycleCallbacks(k);
                        }
                    } catch (Exception var2) {
                        if (!x.a(var2)) {
                            var2.printStackTrace();
                        }
                    }
                }
            }

            b = false;
        }
    }
}
